package dao;

import java.util.List;

import hbt.HibernateUtil;

import org.hibernate.Session;
import org.hibernate.SessionFactory;

import entities.Materia;

public class MateriaDAO {
	
	private static MateriaDAO instancia;
	
	private MateriaDAO(){}
	
	public static MateriaDAO getInstancia()
	{
		if(instancia == null)
			instancia = new MateriaDAO();
		return instancia;
	}
	
	public List<Materia> obtenerMateria() {
		SessionFactory sf =  HibernateUtil.getSessionFactory();
		Session session = sf.openSession();
//		List<Materia>Materias=(List<Materia>)session.createQuery("select * from Materia where a.id=?").setInteger(0, Materia.getId()).list();
		@SuppressWarnings("unchecked")
		List<Materia>Materias=(List<Materia>)session.createQuery("select * from Materia").list();
		return Materias;
	}
	
	@SuppressWarnings("null")
	public List<String> getListaMaterias(){
		List<String> miLista = null;
		List<Materia> listaObj = this.obtenerMateria();
		for (int i=0; i<listaObj.size(); i++){
			miLista.add(listaObj.get(i).getDescripcion());
		}
		return miLista;
	}
}